/*******************************************************************************
*  file    : utils.cpp
*  created : 29.09.2012
*  author  : Slyshyk Oleksiy (alex312@meta.ua)
*******************************************************************************/

#include "utils.hpp"
#include <QTextStream>
#include <QRegExp>

namespace utils
{

QByteArray readFile(const QString& fileName)
{
    QFile file(fileName);
    if (!file.open(QIODevice::ReadOnly))
        {
            return QByteArray();
        }
    return file.readAll();
}

int getBuildNumber(const QString & fileName)
{
    if(QFile::exists(fileName))
        {
            QFile file(fileName);
            file.open(QIODevice::ReadOnly | QIODevice::Text);
            QTextStream data(&file);
            while ( !data.atEnd() )
                {
                    QString line = data.readLine();
                    if(line.contains("BUILD"))
                        {
                            QRegExp re("\\d+");
                            if(re.indexIn(line) != -1)
                                {
                                    QString tmp = re.cap(0);
                                    return tmp.toInt()+1;
                                }
                            else
                                {

                                }
                        }
                }
        }

    return 1;
}

}//namespace utils
